package com.bulletelc.apollopre.module.main;

import com.bulletelc.apollopre.framework.IModel;

/**
 * author: lhl
 * date  : 2017/11/14
 * desc  : TODO
 */

public class MainPresenter extends MainContract.Presenter {
    private MainContract.View view;
    private MainContract.Model model;

    public MainPresenter(MainContract.View view) {
        this.view = view;
        model = new MainModel();
    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {

    }

    @Override
    public void checkVersion() {

        model.checkVersion(new IModel.AsyncCallback() {
            @Override
            public void onSuccess(Object success) {
                view.showUpdateDialog();
            }

            @Override
            public void onError(Object error) {

            }
        });

    }

    @Override
    public void downloadAPK() {
        model.downloadAPK(new MainContract.MainModelCallback() {
            @Override
            public void onStart() {
                view.onLoadingStart();
            }

            @Override
            public void onFinish() {
                view.onLoadingFinish();
            }

            @Override
            public void downloadProgress(long downloadLength, long totalLength, float fraction) {
                view.showLoadingProgress(downloadLength,totalLength,fraction);
            }

            @Override
            public void onSuccess(Object success) {

            }

            @Override
            public void onError(Object error) {
                view.onLoadingError(error);
            }
        });
    }

}
